package b.p.b;

import android.view.View;
import android.view.ViewGroup.LayoutParams;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.n;
import androidx.recyclerview.widget.RecyclerView.z;
import b.i.k.o;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.WeakHashMap;

/* compiled from: ChildHelper */
public class d {
    public final b a;
    public final a b = new a();
    public final List<View> c = new ArrayList();

    /* compiled from: ChildHelper */
    public static class a {
        public long a = 0;
        public a b;

        public void a(int i) {
            if (i >= 64) {
                a aVar = this.b;
                if (aVar != null) {
                    aVar.a(i - 64);
                    return;
                }
                return;
            }
            this.a &= ~(1 << i);
        }

        public int b(int i) {
            a aVar = this.b;
            if (aVar == null) {
                if (i >= 64) {
                    return Long.bitCount(this.a);
                }
                return Long.bitCount(this.a & ((1 << i) - 1));
            } else if (i < 64) {
                return Long.bitCount(this.a & ((1 << i) - 1));
            } else {
                return Long.bitCount(this.a) + aVar.b(i - 64);
            }
        }

        public final void c() {
            if (this.b == null) {
                this.b = new a();
            }
        }

        public boolean d(int i) {
            if (i >= 64) {
                c();
                return this.b.d(i - 64);
            }
            return (this.a & (1 << i)) != 0;
        }

        public void e(int i, boolean z) {
            if (i >= 64) {
                c();
                this.b.e(i - 64, z);
                return;
            }
            long j = this.a;
            boolean z2 = (Long.MIN_VALUE & j) != 0;
            long j2 = (1 << i) - 1;
            this.a = ((j & (~j2)) << 1) | (j & j2);
            if (z) {
                h(i);
            } else {
                a(i);
            }
            if (z2 || this.b != null) {
                c();
                this.b.e(0, z2);
            }
        }

        public boolean f(int i) {
            if (i >= 64) {
                c();
                return this.b.f(i - 64);
            }
            long j = 1 << i;
            long j2 = this.a;
            boolean z = (j2 & j) != 0;
            j2 &= ~j;
            this.a = j2;
            j--;
            this.a = (j2 & j) | Long.rotateRight((~j) & j2, 1);
            a aVar = this.b;
            if (aVar != null) {
                if (aVar.d(0)) {
                    h(63);
                }
                this.b.f(0);
            }
            return z;
        }

        public void g() {
            this.a = 0;
            a aVar = this.b;
            if (aVar != null) {
                aVar.g();
            }
        }

        public void h(int i) {
            if (i >= 64) {
                c();
                this.b.h(i - 64);
                return;
            }
            this.a |= 1 << i;
        }

        public String toString() {
            if (this.b == null) {
                return Long.toBinaryString(this.a);
            }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(this.b.toString());
            stringBuilder.append("xx");
            stringBuilder.append(Long.toBinaryString(this.a));
            return stringBuilder.toString();
        }
    }

    /* compiled from: ChildHelper */
    public interface b {
    }

    public d(b bVar) {
        this.a = bVar;
    }

    public void a(View view, int i, boolean z) {
        if (i < 0) {
            i = ((a0) this.a).b();
        } else {
            i = f(i);
        }
        this.b.e(i, z);
        if (z) {
            i(view);
        }
        a0 a0Var = (a0) this.a;
        a0Var.a.addView(view, i);
        RecyclerView recyclerView = a0Var.a;
        Objects.requireNonNull(recyclerView);
        RecyclerView.L(view);
        recyclerView.T();
        List list = recyclerView.C;
        if (list != null) {
            int size = list.size();
            while (true) {
                size--;
                if (size >= 0) {
                    ((n) recyclerView.C.get(size)).b(view);
                } else {
                    return;
                }
            }
        }
    }

    public void b(View view, int i, LayoutParams layoutParams, boolean z) {
        if (i < 0) {
            i = ((a0) this.a).b();
        } else {
            i = f(i);
        }
        this.b.e(i, z);
        if (z) {
            i(view);
        }
        a0 a0Var = (a0) this.a;
        Objects.requireNonNull(a0Var);
        z L = RecyclerView.L(view);
        if (L != null) {
            if (L.o() || L.u()) {
                L.j &= -257;
            } else {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Called attach on a child which is not detached: ");
                stringBuilder.append(L);
                throw new IllegalArgumentException(c.b.a.a.a.z(a0Var.a, stringBuilder));
            }
        }
        a0Var.a.attachViewToParent(view, i, layoutParams);
    }

    public void c(int i) {
        i = f(i);
        this.b.f(i);
        a0 a0Var = (a0) this.a;
        View childAt = a0Var.a.getChildAt(i);
        if (childAt != null) {
            z L = RecyclerView.L(childAt);
            if (L != null) {
                if (!L.o() || L.u()) {
                    L.b(256);
                } else {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append("called detach on an already detached child ");
                    stringBuilder.append(L);
                    throw new IllegalArgumentException(c.b.a.a.a.z(a0Var.a, stringBuilder));
                }
            }
        }
        a0Var.a.detachViewFromParent(i);
    }

    public View d(int i) {
        return ((a0) this.a).a(f(i));
    }

    public int e() {
        return ((a0) this.a).b() - this.c.size();
    }

    public final int f(int i) {
        if (i < 0) {
            return -1;
        }
        int b = ((a0) this.a).b();
        int i2 = i;
        while (i2 < b) {
            int b2 = i - (i2 - this.b.b(i2));
            if (b2 == 0) {
                while (this.b.d(i2)) {
                    i2++;
                }
                return i2;
            }
            i2 += b2;
        }
        return -1;
    }

    public View g(int i) {
        return ((a0) this.a).a.getChildAt(i);
    }

    public int h() {
        return ((a0) this.a).b();
    }

    public final void i(View view) {
        this.c.add(view);
        a0 a0Var = (a0) this.a;
        Objects.requireNonNull(a0Var);
        z L = RecyclerView.L(view);
        if (L != null) {
            RecyclerView recyclerView = a0Var.a;
            int i = L.q;
            if (i != -1) {
                L.p = i;
            } else {
                View view2 = L.a;
                WeakHashMap weakHashMap = o.a;
                L.p = view2.getImportantForAccessibility();
            }
            recyclerView.l0(L, 4);
        }
    }

    public int j(View view) {
        int indexOfChild = ((a0) this.a).a.indexOfChild(view);
        if (indexOfChild == -1 || this.b.d(indexOfChild)) {
            return -1;
        }
        return indexOfChild - this.b.b(indexOfChild);
    }

    public boolean k(View view) {
        return this.c.contains(view);
    }

    public final boolean l(View view) {
        if (!this.c.remove(view)) {
            return false;
        }
        a0 a0Var = (a0) this.a;
        Objects.requireNonNull(a0Var);
        z L = RecyclerView.L(view);
        if (L != null) {
            a0Var.a.l0(L, L.p);
            L.p = 0;
        }
        return true;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(this.b.toString());
        stringBuilder.append(", hidden list:");
        stringBuilder.append(this.c.size());
        return stringBuilder.toString();
    }
}
